/*
 * Copyright 2009-2010 Belmont Software Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.belmont.backup.client;

import java.util.*;
import com.google.gwt.core.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.rpc.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.*;

public class UIPanel {
    BackupUI main;
    String displayName;
    Button cancelButton;
    Button applyButton;

    public UIPanel(BackupUI main, String displayName) {
        this.main = main;
        this.displayName = displayName;
    }

    public String getName() {
        return displayName;
    }

    public Widget init() {
        return null;
    }

    public void refresh() {
    }

    protected void doApply() {
    }

    protected void doCancel() {
        refresh();
    }

    protected void createTaskLayout(String title, HTML help, MenuBar menu, DockPanel dp, DeckPanel deckPanel, boolean apply, boolean cancel) {
        VerticalPanel tasks = new VerticalPanel();
        DecoratorPanel decoratedMenu = new DecoratorPanel();
        DecoratorPanel decoratedDeck = new DecoratorPanel();
        VerticalPanel deck = new VerticalPanel();
        HorizontalPanel buttons = new HorizontalPanel();

        help.setStyleName("backup-Help");
        dp.add(help, DockPanel.NORTH);

        tasks.add(new HTML("<b>"+title+"<b>"));
        decoratedMenu.add(menu);
        deckPanel.setWidth("100%");
        deck.add(deckPanel);

        if (cancel) {
            cancelButton = new Button("Cancel",
                                      new ClickHandler() {
                                          public void onClick(ClickEvent ev) {
                                              doCancel();
                                          }
                                      });
            buttons.add(cancelButton);
        }

        if (apply) {
            applyButton = new Button("Apply", new ClickHandler() {
                    public void onClick(ClickEvent ev) {
                        doApply();
                    }
                });

            buttons.add(applyButton);
        }

        if (apply || cancel) {
            buttons.setSpacing(5);
            deck.add(buttons);
        }

        deck.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        decoratedDeck.add(deck);
        tasks.add(decoratedMenu);
        tasks.setSpacing(4);
        //decoratedDeck.setWidth("95%");
        dp.add(tasks, DockPanel.WEST);
        dp.add(decoratedDeck, DockPanel.CENTER);
        dp.setCellHorizontalAlignment(decoratedDeck, HasHorizontalAlignment.ALIGN_LEFT);
        dp.setCellVerticalAlignment(decoratedDeck, HasVerticalAlignment.ALIGN_TOP);
        dp.setCellVerticalAlignment(tasks, HasVerticalAlignment.ALIGN_TOP);
        dp.setHeight("100%");
        dp.setWidth("100%");
        deckPanel.showWidget(0);
    }

    protected void addRowToControlPanel(Grid g, int row, String label, Widget widget, String popupHelp) {
        g.setWidget(row, 0, new HTML(label));
        g.setWidget(row, 1, new BackupPopupHelp(popupHelp));
        g.setWidget(row, 2, widget);
        g.getRowFormatter().addStyleName(row, "backup-Controls");
    }
}